<?php if($this->session->userdata('step1') != true){header("Location: ".base_url()."password/error");} else{ ?> <!-- header("Location: err.php?e=404") -->
<body>
<div class="container-fluid">
<div class="row" style="margin-top: 10%; margin-bottom: 10%;">
    <div class="col-lg-4 col-xs-12"></div>
    <div class="col-lg-4 col-xs-12" style="border: 1px solid #F36F00;">
    <div class="row" style="background-color: orange; font-weight: bolder; font-size: 20px; padding: 10px; color: white; text-align: center"><span style="padding: 20px">CÀI ĐẶT LẠI MẬT KHẨU</span></div>
    <div class="row" style="margin: 10px;">
        <label>Bạn muốn cài đặt lại mật khẩu như thế nào?</label>
    </div>
    <div class="row" style="margin: 10px;">
        <div class="col-lg-1" style="margin-top: 10px;">
            <input type="radio" id="radioEmailResetFP" onclick="$('#radioPhoneResetFP').prop('checked', false)">
        </div>
        <div class="col-lg-11">
            <div class="row">
                <div class="col-lg-2">
                    <img class="img-responsive" src="<?php echo base_url() ?>assets/images/message_icon.png">
                </div>
                <div class="col-lg-10">
                    <div class="row">
                        <label>Gửi cho tôi một liên kết cài đặt lại mật khẩu tới</label>
                    </div>
                    <div class="row">
                        <label><?php echo $email ?></label>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="margin: 10px;" id="divPhoneFP">
        <div class="col-lg-1" style="margin-top: 10px;">
            <input type="radio" id="radioPhoneResetFP" onclick="$('#radioEmailResetFP').prop('checked', false)">
        </div>
        <div class="col-lg-11">
            <div class="row">
                <div class="col-lg-2">
                    <img class="img-responsive" src="<?php echo base_url() ?>assets/images/phone_icon.png">
                </div>
                <div class="col-lg-10">
                    <div class="row">
                        <label>Gửi cho tôi một đoạn mã cài đặt lại mật khẩu tới</label>
                    </div>
                    <div class="row">
                        <label><?php echo $phone ?></label>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="text-align: center; color: darkgreen; margin: 5px;" id="divReSetFP"></div>
    <div class="row" style="margin: 20px; text-align: center">
        <span id="spnContinueFP" style="padding: 10px; width: 500px; background-color: darkorange; color: white; font-size: 18px; cursor: pointer; margin: 20px" onclick="sendFP()">Tiếp tục</span>
    </div>
    </div>
    <div class="col-lg-4 col-xs-12"></div>
</div>
</div>
</body>

<script>
    $(document).ready(function(){
        $(document).bind('keypress', function(e) {
            if(e.keyCode==13){
                sendFP();
            }
        });
        isValidPhone();
    });

    function isValidPhone(){
        var phone = "<?php echo $phone ?>";
//        alert(phone);
        if(phone == ''){
            $('#radioEmailResetFP').prop('checked', true);
            $('#spnContinueFP').click();
        }
    }

    function sendFP(){
        var step1 = "<?php if($this->session->userdata('step1') == true){echo 1;} else{echo 0;} ?>";
//        alert(step1);
        if(step1 == 0){
            window.location.href = "<?php echo base_url() ?>password/error";
        }
        else{
            $('#divReSetFP').html("");
            if(!$('#radioEmailResetFP').is(':checked') && !$('#radioPhoneResetFP').is(':checked')){
                $('#divReSetFP').html("<span style='color: red'>Xin vui lòng chọn phương thức để cài đặt lại mật khẩu!</span>");
            }
            else{
                var method = 0;
                if($('#radioPhoneResetFP').is(':checked') ){ //kiem tra neu checkbox khong duoc check
                    method = 1;
                }

                var fone = "<?php echo $fone ?>";
                var url = "<?php echo base_url() ?>";
                var dataString = "fone="+fone+"&method="+method;
                $.ajax({
                    type: "POST",
                    url: url+"users/setStep2FP",
                    data: dataString,
                    success: function(x){
//                alert(x);
                        if(method == 0){
                            window.location.href = "<?php echo base_url() ?>password/recover?email=<?php echo $email ?>";
                        }
                        else{
                            window.location.href = "<?php echo base_url() ?>password/recover?phone=<?php echo $phone ?>";
                        }
                    }
                });
            }
        }
    }
</script>
<?php } ?>